<script src="/public/static/js/jquery.min.js"></script>
<script src="/public/static/plugin/layer/layer.js"></script>
<style>
	.contain{
		margin-top: 10px;
		padding-left: 10px;
		font-size:13px;
		margin-right: 10px;
		font-family: 微软雅黑, "Source Sans Pro", sans-serif;
		width: 700px;
		margin-top: 30px;
	}
	.from_i_s{
		height: 20px;
        line-height: 20px;
        padding: 0px 5px;
        width: 120px;
        border-radius: 4px;
        border: 1px solid #ccc;
	}
	.from_c{
		border-radius: 4px;
        border: 1px solid #ccc;
	}

	.div_line{
    	margin-left: 15px;
    	padding-bottom: 30px;
    }
    .div_line_one{
    	float: left;
    	width: 80px;
    	text-align: right;
    }
    .div_line_two{
    	width: 85%;
    	float: left;
    }
	.div_line_two ul{
    	display: inline-block;
        padding: 0;
        margin: 0;
        line-height: 30px;
    }
    .div_line_two ul li{
    	list-style: none;
        display: inline-block;
        margin-right: 10px;
        padding: 0;
        
    }
    h4 { font-size: 13px; font-weight: normal; color: #666; text-align: right; vertical-align: top; display: inline-block; *display: inline/*IE7*/;
 margin-right: 1%; *zoom: 1;margin-left: 5px;margin-top: 12px;margin-bottom: 5px;color: #009f95;font-weight: bold;
}
a.ncap-btn-big {text-decoration: none;font-weight: bold 14px/20px "microsoft yahei", arial; color: #FFFFFF; background-color: #5cb85c; text-align: center; vertical-align: middle; display: inline-block; 
height: 20px; padding: 7px 19px; border: solid 1px #5cb85c; border-radius: 3px; cursor: pointer; }
a:hover.ncap-btn-big { text-decoration: none; color: #FFFFFF; background-color: #5cb85c; box-shadow: 0 0 0 2px rgba(82, 168, 236, 0.15); }
    

</style>

<div class="contain">
	    	
	<div class="div_line">
        <div class="div_line_one">平台：</div>
        <div class="div_line_two">
            <select name="special_id" class="from_i_s" data-url='<{$speUrl}>'>
            	<option value="">请选择</option>
            	<{foreach from=$specialList item=item key=key}>
            	<option value="<{$key}>"><{$item}></option>
            	<{/foreach}>
            </select>
        </div>
    </div>
    
    <div class="div_line" id="server" style="display: none;">
        <div class="div_line_one" style="padding-top: 10px;">选择服务器：</div>
        <div class="div_line_two">
        	<h4>
				<input id="cls_server" cka='server' type="checkbox">
				<label>全选</label>
			</h4><br />
            <ul id="server_ul">
            	<!--<li>
                    <input class="from_c" ck='server' name="server_id[]" type="checkbox" value=""/>
                    <label for="">服务器1</label>
                </li>
                <li>
                    <input ck='server' name="server_id[]" type="checkbox" value=""/>
                    <label for="">服务器1</label>
                </li>-->
            </ul>                               
        </div>
    </div>
    
    
    <div class="div_line" id="channel" style="display: none;">
        <div class="div_line_one" style="padding-top: 10px;">选择渠道：</div>
        <div class="div_line_two">
        	<h4>
				<input id="cls_channel" cka='channel' type="checkbox">
				<label>全选</label>
			</h4><br />
            <ul id="channel_ul">
            	<!--<li>
                    <input class="from_c" ck='channel' name="channel_id[]" type="checkbox" value=""/>
                    <label for="">渠道1</label>
                </li>
                <li>
                    <input class="from_c" ck='channel' name="channel_id[]" type="checkbox" value=""/>
                    <label for="">渠道1</label>
                </li>-->
               
            </ul>                               
        </div>
    </div>
    
    
	<div class="div_line">
		<input type="hidden" name="ids" id="ids" value="<{$ids}>" />
		<a href="JavaScript:void(0);" style="margin-top: 30px;margin-left: 70%;"  class="ncap-btn-big" id="submitBtn" data-url="<{$url}>">确认提交</a>
	</div>

</div>



<script>
    $(document).ready(function(){
		$(":checkbox[cka]").click(function(){
			var cks = $(":checkbox[ck='"+$(this).attr("cka")+"']");
			if($(this).is(':checked')){
				cks.each(function(){$(this).prop("checked",true);});
			}else{
				cks.each(function(){$(this).removeAttr('checked');});
			}
		});
		
		
		$("select[name='special_id']").change(function(){
			var special_id = $(this).val();
			var url = $(this).attr('data-url');
			if(special_id == ''){
				$("#server").hide();
				$("#channel").hide();
				return false;
			}
			$.ajax({
    		    type : 'POST',
    		    url : url,
			    data : {'special_id':special_id},
			    dataType :'JSON',
			    success : function(res){
				    if(res.status == 1){
				    	$("#server").show();
				        $("#channel").show();
				        var server = ''
				        var channel = '';
				        for (var i=0;i<res.data.server.length;i++){
				        	server += '<li><input class="from_c" ck="server" name="server_id[]" type="checkbox" value="'+res.data.server[i]["server_id"]+'"/><label for="'+res.data.server[i]["server_name"]+'">'+res.data.server[i]["server_name"]+'</label></li>'
				        }
				        $("#server_ul").html(server);
				        
				        for (var i=0;i<res.data.channel.length;i++){
				        	channel += '<li><input class="from_c" ck="channel" name="channel_id[]" type="checkbox" value="'+res.data.channel[i]["id"]+'"/><label for="'+res.data.channel[i]["channel_name"]+'">'+res.data.channel[i]["channel_name"]+'</label></li>'
				        }
				        $("#channel_ul").html(channel);
				    }else{
					   layer.msg('操作失败', {icon: 2,time: 2000});
				    }
			    }
		    });
		});
		
	});
	
	
	var flag = true;
    $("#submitBtn").click(function(){
    	var special_id = $("#special_id").val();
    	if(special_id == ''){
    		layer.msg('请选择专服', {icon: 2,time: 2000});
        	return false;
    	}
    	
    	var arr = new Array();
        $("input[name='server_id[]']:checkbox[checked]").each(function(i){
            arr[i] = $(this).val();
        });
        var servers = arr.join(",");
        if(servers == ''){
        	layer.msg('请选择服务器', {icon: 2,time: 2000});
        	return false;
        }
        
        var brr = new Array();
        $("input[name='channel_id[]']:checkbox[checked]").each(function(i){
            brr[i] = $(this).val();
        });
        var channel = brr.join(",");
        if(channel == ''){
        	layer.msg('请选择渠道', {icon: 2,time: 2000});
        	return false;
        }
        
        //console.log(servers);    
        if(!flag){
    		return false;
    	}
    	flag = false;
    	$("#submitBtn").text('提交中...');
    	var index = layer.load(0, {shade: false});
        
        var url = $(this).attr('data-url');
        //console.log(url); 
        var ids = $("#ids").val();
    	$.ajax({
    		type : 'POST',
    		url : url,
			data : {'servers':servers,'channel':channel,'ids':ids},
			dataType :'JSON',
			success : function(res){
				flag = true;
				if(res.status == 1){
					layer.close(index);
					$("#submitBtn").text('确认提交');
					window.parent.call_back();
				}else{
					layer.msg('操作失败', {icon: 2,time: 2000});
				}
			}
		});
    });
    
    
</script>